#include "msgport.h"
#include "common.h"

MsgQueue* MsgQueue::s_MsgQueue;

bool MsgQueue::PushMsg(MSG_HEAD* msgHead, int msgSize)
{
	m_Mutex.Lock();
	
	CNetMsg* pNetMsg = new CNetMsg;
	memcpy(pNetMsg, msgHead, msgSize);
	m_MsgDeque.push_back((MSG_HEAD*)(pNetMsg));

	m_Mutex.Unlock();
	return true;
}

MSG_HEAD* MsgQueue::PopMsg()
{
	m_Mutex.Lock();
	
	MSG_HEAD* msgHead = this->m_MsgDeque.front();
	this->m_MsgDeque.pop_front();


	m_Mutex.Unlock();
	return msgHead;

}

MsgQueue* MsgQueue::GetInstance()
{
	if(s_MsgQueue == NULL)
		s_MsgQueue = new MsgQueue();
	return s_MsgQueue;
}

int MsgQueue::GetSize()
{
	m_Mutex.Lock();
	int size = this->m_MsgDeque.size();
	m_Mutex.Unlock();
	return size;
}
